import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2;

/**
 * System - 系统配置
 * @date: 2019-11-1

 * @version: 1.0.0
 */
import React, { Component } from 'react';
import { Col, Form, Input, Row, Select } from 'antd';
import { Bind } from 'lodash-decorators';
import Upload from 'components/Upload/UploadButton';
import intl from 'utils/intl';
import { BKT_PUBLIC } from 'utils/config';
var FormItem = Form.Item;
var formLayout = {
  labelCol: {
    span: 6
  },
  wrapperCol: {
    span: 18
  }
};
var System = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec6 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_Component) {
  _inherits(System, _Component);

  var _super = _createSuper(System);

  function System(props) {
    var _this;

    _classCallCheck(this, System);

    _this = _super.call(this, props);
    _this.state = {};
    return _this;
  }

  _createClass(System, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          getFieldDecorator = _this$props.form.getFieldDecorator,
          _this$props$config = _this$props.config,
          _this$props$config$da = _this$props$config.data,
          data = _this$props$config$da === void 0 ? [] : _this$props$config$da,
          _this$props$config$lo = _this$props$config.lov,
          _this$props$config$lo2 = _this$props$config$lo.menuLayout,
          lovMenuLayout = _this$props$config$lo2 === void 0 ? [] : _this$props$config$lo2,
          _this$props$config$lo3 = _this$props$config$lo.menuLayoutTheme,
          lovMenuLayoutTheme = _this$props$config$lo3 === void 0 ? [] : _this$props$config$lo3,
          _this$props$config$lo4 = _this$props$config$lo.roleMergeFlag,
          lovRoleMergeFlag = _this$props$config$lo4 === void 0 ? [] : _this$props$config$lo4;
      var iconFileList = [];
      var faviconFileList = [];

      if (data.length > 0) {
        data.forEach(function (item) {
          switch (item.configCode) {
            case 'LOGO':
              iconFileList = [{
                uid: '-1',
                name: item.fileName,
                status: 'done',
                url: item.configValue
              }];
              break;

            case 'FAVICON':
              faviconFileList = [{
                uid: '-1',
                name: item.fileName,
                status: 'done',
                url: item.configValue
              }];
              break;

            default:
              break;
          }
        });
      }

      var title = this.findConfigField('TITLE', data);
      var logo = this.findConfigField('LOGO', data);
      var favicon = this.findConfigField('FAVICON', data);
      var menuLayout = this.findConfigField('MENU_LAYOUT', data);
      var menuLayoutTheme = this.findConfigField('MENU_LAYOUT_THEME', data);
      var roleMergeFlag = this.findConfigField('ROLE_MERGE', data);
      return /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpfm.config.model.config.title').d('系统标题')
      }, formLayout), getFieldDecorator('title', {
        initialValue: title,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cpfm.config.model.config.title').d('系统标题')
          })
        }, {
          max: 80,
          message: intl.get('cpaas.common.validation.max', {
            max: 80
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, null))))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpfm.config.model.config.logo').d('LOGO'),
        extra: intl.get('cpaas.common.upload.support', {
          type: '*.png;*.jpeg'
        }).d('上传格式：*.png;*.jpeg')
      }, formLayout), /*#__PURE__*/React.createElement(Upload, {
        accept: ".jpeg,.png",
        fileType: "image/jpeg,image/png",
        single: true,
        bucketName: BKT_PUBLIC,
        bucketDirectory: "cpfm05",
        onUploadSuccess: this.onUploadSuccess,
        fileList: iconFileList,
        onRemoveSuccess: this.onCancelSuccess
      })), /*#__PURE__*/React.createElement(FormItem, {
        wrapperCol: {
          span: 15,
          offset: 7
        }
      }, getFieldDecorator('logo', {
        initialValue: logo
      })( /*#__PURE__*/React.createElement("div", null))))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpfm.config.model.config.favicon').d('favicon'),
        extra: intl.get('cpaas.common.upload.support', {
          type: '*.png;*.ico'
        }).d('上传格式：*.png;*.ico')
      }, formLayout), /*#__PURE__*/React.createElement(Upload, {
        single: true,
        accept: ".png,.ico",
        fileType: "image/png,image/vnd.microsoft.icon,image/x-icon\t",
        bucketName: BKT_PUBLIC,
        bucketDirectory: "cpfm05",
        onUploadSuccess: this.handleFaviconUploadSuccess,
        fileList: faviconFileList,
        onRemoveSuccess: this.handleCancelFaviconUploadSuccess
      })), /*#__PURE__*/React.createElement(FormItem, {
        wrapperCol: {
          span: 15,
          offset: 7
        }
      }, getFieldDecorator('favicon', {
        initialValue: favicon
      })( /*#__PURE__*/React.createElement("div", null))))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpfm.config.model.config.menuLayout').d('菜单布局')
      }, formLayout), getFieldDecorator('menuLayout', {
        initialValue: menuLayout,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cpfm.config.model.config.menuLayout').d('菜单布局')
          })
        }]
      })( /*#__PURE__*/React.createElement(Select, null, lovMenuLayout.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          key: item.value,
          value: item.value
        }, item.meaning);
      })))))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpfm.config.model.config.menuLayoutTheme').d('菜单布局主题')
      }, formLayout), getFieldDecorator('menuLayoutTheme', {
        initialValue: menuLayoutTheme,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cpfm.config.model.config.menuLayoutTheme').d('菜单布局主题')
          })
        }]
      })( /*#__PURE__*/React.createElement(Select, null, lovMenuLayoutTheme.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          key: item.value,
          value: item.value
        }, item.meaning);
      })))))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 16
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cpfm.config.model.config.roleMergeFlag').d('角色合并')
      }, formLayout), getFieldDecorator('roleMergeFlag', {
        initialValue: roleMergeFlag,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('cpfm.config.model.config.roleMergeFlag').d('角色合并')
          })
        }]
      })( /*#__PURE__*/React.createElement(Select, null, lovRoleMergeFlag.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          key: item.value,
          value: item.value
        }, item.meaning);
      })))))));
    }
    /**
     * 从配置列表查找配置项
     * @param {Number|String} field 查询配置字段的 ID 或 Code
     * @param {Array} data 获取到的原配置数组
     */

  }, {
    key: "findConfigField",
    value: function findConfigField(field, data) {
      if (data.length > 0) {
        var dataFilter = data.find(function (item) {
          return item.configCode === field;
        });
        return dataFilter ? dataFilter.configValue : null;
      }
    } // 上传图片成功

  }, {
    key: "onUploadSuccess",
    value: function onUploadSuccess(file) {
      var form = this.props.form;

      if (file) {
        form.setFieldsValue({
          logo: file.response
        });
      }
    } // 删除图片成功

  }, {
    key: "onCancelSuccess",
    value: function onCancelSuccess() {
      var form = this.props.form;
      form.setFieldsValue({
        logo: ''
      });
    }
    /**
     * 上传 favicon 成功
     */

  }, {
    key: "handleFaviconUploadSuccess",
    value: function handleFaviconUploadSuccess(file) {
      var form = this.props.form;

      if (file) {
        form.setFieldsValue({
          favicon: file.response
        });
      }
    }
    /**
     * 删除 favicon 成功
     */

  }, {
    key: "handleCancelFaviconUploadSuccess",
    value: function handleCancelFaviconUploadSuccess() {
      var form = this.props.form;
      form.setFieldsValue({
        favicon: ''
      });
    }
  }]);

  return System;
}(Component), (_applyDecoratedDescriptor(_class2.prototype, "findConfigField", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "findConfigField"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "onUploadSuccess", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "onUploadSuccess"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "onCancelSuccess", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "onCancelSuccess"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleFaviconUploadSuccess", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "handleFaviconUploadSuccess"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleCancelFaviconUploadSuccess", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "handleCancelFaviconUploadSuccess"), _class2.prototype)), _class2)) || _class);
export { System as default };